﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Cesave.Domain.PermisosModule.Entities;
using Cesave.Infrastructure.Data.PermisosModule.Context;
using Cesave.Infrastructure.CrossCutting.Logging;
using Cesave.Domain.PermisosModule.Contracts.Areas;
using Cesave.Infrastructure.Data.PermisosModule.Repositories;
using Cesave.Domain.PermisosModule.Contracts.Afianzadoras;

namespace Cesave.Infrastructure.Data.PermisosModule.Tests.RepositoriesTests
{
	[TestClass]
	public class AreaRepositoryTests
		: GenericRepositoryTestsBase<Area>
	{
		public override System.Linq.Expressions.Expression<Func<Area, bool>> FilterExpression
		{
			get
			{
				return a => a.AreaId == 1;
			}
		}

		public override System.Linq.Expressions.Expression<Func<Area, int>> OrderByExpression
		{
			get
			{
				return a => a.AreaId;
			}
		}

		[TestMethod]
		[ExpectedException(typeof(ArgumentNullException))]
		public void FindAreasByJunta_Null_Specification_Throws_ArgumentNullException()
		{
			// Arrange
			IPermisosModuleContext context = GetContext();
			ITraceManager traceManager = GetTraceManager();
			IAreaRepository repository = new AreaRepository(context, traceManager);

			// Act
			var actual = repository.FindAreasByJunta(null);
		}

		[TestMethod]
		[ExpectedException(typeof(ArgumentException))]
		public void FindAreasByJunta_Empty_Guid_Throws_ArgumentNullException()
		{
			// Arrange
			IPermisosModuleContext context = GetContext();
			ITraceManager traceManager = GetTraceManager();
			IAreaRepository repository = new AreaRepository(context, traceManager);

			AreasByJuntaSpecification specification = new AreasByJuntaSpecification(Guid.Empty);
			// Act
			var actual = repository.FindAreasByJunta(specification);
		}

		[TestMethod]
		public void FindAreasByJunta_Invoke()
		{
			// Arrange
			IPermisosModuleContext context = GetContext();
			ITraceManager traceManager = GetTraceManager();
			IAreaRepository repository = new AreaRepository(context, traceManager);

			AreasByJuntaSpecification specification = new AreasByJuntaSpecification(new Guid("C9760433-39E5-4FE4-A17E-EDE111734C65"));

			// Act
			var actual = repository.FindAreasByJunta(specification);

			// Assert
			Assert.IsNotNull(actual);
			Assert.AreEqual(3, actual.Count());
		}

	}
}